package com.yiwei.jmx.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yiwei.jmx.R;
import com.yiwei.jmx.activity.WebViewActivity;
import com.yiwei.jmx.api.model.DealIndexModel;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class HomeTwoAdapter extends ItemAdapter<DealIndexModel.DataBean.RookieBean, HomeTwoAdapter.DefaultHolder> {


    //    private int[] img_res = new int[]{R.mipmap.img_home_type_question, R.mipmap.img_home_type_fengkong, R.mipmap.img_home_type_security, R.mipmap.img_home_type_register, R.mipmap.img_home_type_quick, R.mipmap.img_home_type_fee};
    private Context context;

    //    private String[][] text_string={
//            {"常见问题","为您排忧解惑"},
//            {"最强风控","为您保驾护航"},
//            {"安全保障","为您信息加密"},
//            {"便捷注册","让您用得舒心"},
//            {"专业快捷","让您借得安心"},
//            {"超低费率","让您笑得开心"}
//    };
    public HomeTwoAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_home_two, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
//        Glide.with(context).load(img_res[position]).into(holder.imgIcon);
//        holder.txtTitle.setText(text_string[position][0]);
//        holder.txtDesc.setText(text_string[position][1]);
        DealIndexModel.DataBean.RookieBean item = getItem(position);
//        GlideUtil.loadImg(context, item.img, holder.layoutTotal);
        Glide.with(context).load(item.img).into(holder.imgIcon);
        holder.txtTitle.setText(item.title);
        holder.txtDesc.setText(item.desc);
        holder.layoutTotal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, WebViewActivity.class);
                intent.putExtra("title", "新手必读");
                intent.putExtra("url", item.link);
                context.startActivity(intent);
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        //        @BindView(R.id.txt_title)
//        TextView txtTitle;
//        @BindView(R.id.txt_desc)
//        TextView txtDesc;
        @BindView(R.id.img_icon)
        ImageView imgIcon;
        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.txt_desc)
        TextView txtDesc;
        @BindView(R.id.layout_total)
        LinearLayout layoutTotal;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onSuccess();
    }
}
